package com.dfd.shiro.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("userController")
public class UserController {


    //用户登陆
    @RequestMapping("userLogin")
    @ResponseBody
    public Boolean userLogin(String uname,String pwd,@RequestParam(defaultValue =  "false") Boolean chk) {
        //获取subject对象
        Subject subject = SecurityUtils.getSubject();
        /**
         * 调用subject的login方法完成登录认证
         */
        //创建Token对象存储要校验的用户数据
        AuthenticationToken token = new UsernamePasswordToken(uname, pwd,chk);
        //登录认证
        try {
            subject.login(token);
            //返回
            return true;
        }catch (AuthenticationException e){
            return false;
        }
    }



}
